home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / TSRSH.ASM < prev    next >
Assembly Source File  |  1987-02-02  |  27KB  |  1,100 lines

  1. PAGE    60,132
  2. TITLE    Ram-Resident Program Shell, Preliminary Version (Lesson 2)
  3. SUBTTL    Date 02-02-87 -- Tutorial for Microsoft Forum  Version 0.03
  4. ;-----------------------------------------------------------------------------
  5. ;    Ram-Resident Program Shell
  6. ;
  7. ;
  8. ;The software, documentation and source code are: 
  9. ;    (C) Copyright 1986, 1987
  10. ;    Chip Rabinowitz
  11. ;    All Rights Reserved 
  12. ;    51 East Rogues Path
  13. ;    Huntington Station NY 11746
  14. ;    Assistant SysOp, Microsoft Forum, Compuserve PPN 76703,350
  15. ;COPYRIGHT NOTICE AND WARRANTY INFORMATION 
  16. ;----------------------------------------- 
  17. ;This document ("the source code"), other accompanying written and disk-based
  18. ;notes and specifications ("the documentation"), and all referenced and related
  19. ;program files accompanying the source code and the documentation ("the
  20. ;software") are copyrighted by Chip Rabinowitz.  
  21. ;
  22. ;This program has been uploaded to Compuserve as part of a Tutorial in how
  23. ;to write Terminate-But-Stay-Resident programs, being conducted on
  24. ;Compuserve's Microsoft Special Interest Group during early 1987/
  25. ;
  26. ;This code (and all other code uploaded by the Copyright Holder as a 
  27. ;part of this TSR Tutorial) may be used with the following restrictions: 
  28. ;
  29. ;(1) If all or part of this code is used as part of a software package of 
  30. ;ANY kind, the following acknowledgement must be used in the Documentation 
  31. ;accompanying said package:
  32. ;
  33. ;    'Parts of the Resident Program Management for this Product are'
  34. ;    'Copyright (C) 1986, 1987 by Chip Rabinowitz, and are incorporated'
  35. ;    'into this product courtesy of the Ringmaster Development Team'
  36. ;
  37. ;(2) If all or part of this code is used as part of a software package that
  38. ;is placed in the public domain, no further restrictions apply.
  39. ;
  40. ;(3) If all or part of this code is used as part of a software package that
  41. ;is being distributed as 'shareware', a one-time-only donation of $10 will be
  42. ;accepted for the express purpose of continuing research into TSR standards.
  43. ;Note that this is a voluntary contribution, and should be sent to the
  44. ;Ringmaster Development Team at the address printed above.
  45. ;
  46. ;(4) If all or part of this code is used as part of a software package that
  47. ;will be distributed as a commercial product, a one-time-only payment of
  48. ;$25 will be accepted the express purpose of continuing research into TSR 
  49. ;standards.  Note that in THIS CASE ONLY, this is not a voluntary 
  50. ;contribution.  Commercial Developers are REQUIRED to make payment prior to
  51. ;incorporating these routines into their product.
  52. ;
  53. ;No copy of the source code may be distributed or given away without the
  54. ;accompanying documentation; and this notice must not be removed. 
  55. ;There is no warranty of any kind associated with this software, and the
  56. ;copyright owner is not liable for damages of any kind.  By using this
  57. ;software, you agree to this. 
  58. ;
  59.  
  60. XON     equ    11h
  61. XOFF    equ    13h
  62. TRUE    equ    1
  63. FALSE   equ    0
  64. CR    equ    0dh
  65. LF    equ    0ah
  66. TAB    equ    9
  67.  
  68.  
  69. HOTKEYON    equ    01h    ;hot key pressed
  70. SHIFTSON    equ    02h    ;shift states match
  71. TSRACTIVE    equ    04h    ;tsr is running in foreground
  72. INT28ACTIVE    equ    08h    ;INT28 routine is running in background
  73.  
  74. KB_DATA    equ    60h
  75. KB_CTL    equ    61h
  76. KB_FLG1    equ    17h
  77. KB_FLG2    equ    18h
  78. BIOS_DATA    equ    40h
  79.  
  80. code segment para public 'CODE'
  81.     org 100h
  82.     assume    cs:code, ds:code, es:code
  83. start:    jmp    begin
  84.  
  85.     db    1bh,'[2J'
  86. cpyrt    db    'Ram-Resident Program Shell, Preliminary Version (Lesson 2)',
  87.     db    CR,LF,LF
  88.     db    'Copyright (C) 1986, 1987 Chip Rabinowitz',
  89.     db    CR,LF,'All Rights Reserved',CR,LF,LF,'$'
  90. hello    db    'Hello World!',CR,LF,'$'
  91. bad_dos_msg    db    'Incompatible DOS version .... Aborting!',07h,CR,LF,'$'
  92.  
  93. tsr_parms:
  94.     PSP    dw    ?    ;PSP of TSR
  95.     OLDPSP    dw    ?    ;location to save current PSP
  96.     DTA    dd    ?    ;DTA of TSR
  97.     OLDDTA    dd    ?    ;location to save current DTA
  98.     DSEG    dw    ?    ;TSR's Data Segment
  99.     SSEG    dw    ?    ;TSR's Stack Segment ....
  100.     SPTR    dw    0fffeh    ;.... and Stack Pointer
  101.     ISSEG    dw    0    ;interrupted SS ...
  102.     ISPTR    dw    0    ;..... and SP
  103.     SHIFTST    db    0    ;Shift State to Activate
  104.     HOTKEY    db    0ffh    ;scan code to activate
  105.     STATUS    dw    0    ;current status words
  106.     POPUP    dd    0    ;far pointer to popup routine
  107.  
  108. intflags    db    0
  109. ININT13        equ    04h    ;Bios disk interrupt
  110. ININT21        equ    08h    ;DOS interrupt
  111.  
  112. dosversion    db    0    ;current version of DOS
  113. waitcount    db    0    ;wait to activate count
  114.  
  115. indosflag    dd    0    ;Pointer to INDOS flag
  116. doscriterr    dd    0    ;Pointer to DOS Critical Error Flag
  117.  
  118. dossseg        dw    0    ;pointer to dos stack segment
  119. dossptr        dw    0    ;pointer to dos stack pointer
  120. dossize        dw    0    ;dos stack size
  121.  
  122. dos21funcs    label    byte
  123.     db    0,    0,    0,    0,    0,    0,    0,    0    ;0-7
  124.     db    0,    0,    0,    0,    0,    0ffh,    0ffh,    0ffh    ;8-f
  125.     db     0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh    ;10-17
  126.     db    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh    ;18-1f
  127.     db    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0,    0ffh    ;20-27
  128.     db    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0    ;28-2f
  129.     db    0ffh,    0,    0,    0,    0,    0,    0ffh,    0ffh    ;30-37
  130.     db    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh    ;38-3f
  131.     db    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh    ;40-47
  132.     db    0,    0,    0,    0,    0ffh,    0,    0ffh,    0ffh    ;48-4f **
  133.     db    0,    0,    0,    0,    0ffh,    0,    0ffh,    0ffh    ;50-57
  134.     db    0,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0,    0    ;58-5f
  135.     db    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh,    0ffh    ;60-67
  136.  
  137. ;
  138. ; ***************************************************************************
  139. ;    These are the bios interrupt vectors
  140. ;
  141.  
  142. BIOSI8    equ    08h        ;Bios Timer interrupt
  143. BIOSI9    equ    09h        ;BIOS Hardware Keyboard interrupt
  144. BIOSIB    equ    0Bh
  145. BIOSIC    equ    0Ch
  146. BIOSI10    equ    10h
  147. BIOSI13    equ    13h        ;Bios Disk interrupt
  148. BIOSI14    equ    14h
  149. BIOSI15    equ    15h
  150. BIOSI16    equ    16h        ;Bios Keyboard interrupt
  151. BIOSI17    equ    17h
  152. BIOSI1C    equ    1Ch
  153. DOSI21    equ    21h        ;DOS service router interrupt
  154. DOSI28    equ    28h        ;DOS Idle interrupt
  155. DOSI33    equ    33h        ;mouse interrupt
  156. BIOSI1B    equ    1Bh
  157. DOSI23    equ    23h
  158. DOSI24    equ    24h
  159. ;
  160. oldint8        dd    0    ;BIOS Hardware Timer Interrupt
  161.         db    BIOSI8
  162.         dw    offset newint8    ;replacement vector
  163. oldint9        dd    0    ;BIOS Hardware Keyboard Interrupt
  164.         db    BIOSI9
  165.         dw    offset newint9    ;replacement vector
  166. oldint13    dd    0    ;BIOS Disk Interrupt
  167.         db    BIOSI13
  168.         dw    offset newint13    ;replacement vector
  169. oldint16    dd    0    ;BIOS Software Keyboard Interrupt
  170.         db    BIOSI16
  171.         dw    offset newint16    ;replacement vector
  172. oldint21    dd    0    ;DOS Services Interrupt
  173.         db    DOSI21
  174.         dw    offset newint21    ;replacement vector
  175. oldint28    dd    0    ;DOS Idle Interrupt
  176.         db    DOSI28
  177.         dw    offset newint28    ;replacement vector
  178. oldint1B    dd    0    ;control-C vector
  179.         db    BIOSI1B
  180.         dw    offset intret    ;replacement vector
  181. oldint23    dd    0    ;control-C vector
  182.         db    DOSI23
  183.         dw    offset intret    ;replacement vector
  184. oldint24    dd    0    ;critical error vector
  185.         db    DOSI24
  186.         dw    offset newint24    ;replacement vector
  187.  
  188. ;
  189. ; ***************************************************************************
  190. ;    Function to restore interrupts.
  191. ;
  192. ;    If AX=0, this function does popup-interrupts (1B, 23 and 24)
  193. ;    If AX=anything else, this function does initial interrupts
  194. ;
  195. restore_int proc near
  196.     push    ds
  197.     push    ax
  198.     push    dx
  199.     push    si
  200.     push    di
  201.     push    cx
  202.     mov    di,7            ;7 bytes per structure
  203.  
  204.     or    ax,ax
  205.     jnz    restore1
  206.  
  207.     mov    cx,3            ;three times through
  208.     mov    si,offset oldint1B    ;start at table beginning
  209.     jmp    restore_loop
  210. restore1:
  211.     mov    cx,06h            ;six interrupts!
  212.     mov    si,offset oldint8    ;top of table
  213.  
  214. restore_loop:
  215.     push    cx
  216.     push    di            ;save structure size
  217.     push    ds
  218.     mov    al,4[si]        ;interrupt number
  219.     mov    dx,[si]            ;IP of interrupt vector
  220.     mov    ds,2[si]        ;CS of interrupt vector
  221.     mov    ah,25h            ;set interrupt vector function
  222.     int    21h
  223.     pop    ds
  224.     xor    ax,ax            ;clear this entry from table
  225.     mov    [si],ax            ;so it shows not used
  226.     mov    2[si],ax
  227.     pop    di            ;get size back
  228.     add    si,di            ;do it again
  229.     pop    cx
  230.     loop    restore_loop
  231.  
  232.     pop    cx
  233.     pop    di
  234.     pop    si
  235.     pop    dx
  236.     pop    ax
  237.     pop    ds
  238.     ret
  239. restore_int endp
  240. ;
  241. ; ***************************************************************************
  242. ;    Function to set interrupts.
  243. ;
  244. ;    If AX=0, this function does popup-interrupts (1B, 23 and 24)
  245. ;    If AX=anything else, this function does initial interrupts
  246. ;
  247. setup_int proc near
  248.     push    es
  249.     push    ax
  250.     push    bx
  251.     push    dx
  252.     push    di
  253.     push    si
  254.     push    cx
  255.     mov    di,7            ;7 bytes per structure
  256.  
  257.     or    ax,ax
  258.     jnz    setup1